<template>
  <div class="toast">
    <!-- 判断传过来的值是什么类型，展示相应的样式
         提示类型 ‘success’ ‘wraning’ ‘danger’
    -->
    <i
      :class="
        type === 'success'
          ? 'iconfont icon-toast_chenggong'
          : type === 'danger'
          ? 'iconfont icon-toast-shibai_huaban'
          : 'iconfont icon-toast-jinggao'
      "
    ></i>
    <span>{{ msg }}</span>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "Toast",
  data() {
    return {};
  },
  computed: {
    ...mapState({
      msg: (state) => state.showToast.msg,
      type: (state) => state.showToast.type,
    }),
  },
};
</script>

<style lang="scss" scoped>
.toast {
  background-color: #edf2fc;
  position: fixed;
  left: 50%;
  top: 0;
  transform: translate(-50%);
  padding: 10px 20px;
  border-radius: 6px;
  box-shadow: 0px 0px 10px #fff;
  i {
    margin-right: 8px;
  }
  .icon-toast_chenggong {
    color: green;
  }
  .icon-toast-jinggao {
    color: orange;
  }
  .icon-toast-shibai_huaban {
    color: red;
  }
}
</style>
